package com.djl.zenithbite.service.user.impl;

import com.djl.zenithbite.entity.LoginCredentials;
import com.djl.zenithbite.entity.LoginCredentialsExample;
import com.djl.zenithbite.repository.LoginCredentialsMapper;
import com.djl.zenithbite.service.user.UserCredentialsService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.Optional;

@Service
public class UserCredentialsServiceImpl implements UserCredentialsService {

    @Autowired
    private LoginCredentialsMapper loginCredentialsMapper;

    @Override
    public LoginCredentials findLoginCredentials(String token) {
        LoginCredentialsExample example = new LoginCredentialsExample();
        LoginCredentialsExample.Criteria criteria = example.createCriteria();
        criteria.andCredentialEqualTo(token);
        return Optional.ofNullable(loginCredentialsMapper.selectByExample(example)).orElse(new ArrayList<>()).stream().findFirst().orElse(null);
    }
}
